<template>
	<view>
		<u-navbar title-color="#fff" :borderBottom="false" titleColor="#000000" :title="title" backIconSize="40"
			back-icon-color="#000000" :background="background"></u-navbar>
		<view class="top">
			<view class="left">
				<view class="name">
					{{title}}
				</view>
				<view class="text">
					蜂巢稍纵即逝，请快速选择心仪蜂巢
				</view>
			</view>
		</view>
		<view class="notice">
			<u-notice-bar color="#92662A" mode="vertical" @end="doBuyList" :volumeIcon="false" :moreIcon="false"
				bgColor="transparent" :more-icon="true" :list="notice"></u-notice-bar>
		</view>
		<view class="content">
			<view v-if="list.length>0">
				<view class="list" v-if="item.show" v-for="(item,index) in list" :key="index">
					<view class="number">
						<view class="down">
							信用等级
						</view>
						<view class="up font">
							{{item.price}} <text>Fmb</text>
						</view>
						<view class="text">
							当前价值
						</view>
					</view>
					<view class="icon" @click="doBuy(item,index)">
						<image src="../static/c2.png" mode=""></image>
					</view>
				</view>
			</view>
			<view v-else class="nonetow">
				<image src="../static/img.png" mode=""></image>
			</view>
		</view>
		<u-popup v-model="logistics" close-icon-pos="top-left" mode="bottom" :closeable="true" borderRadius="10">
			<view class="fight">
				<view class="title_item">
					恭喜抢购蜂巢成功
				</view>
				<view class="icon">
					<image src="/static/image/p0.png" mode=""></image>
				</view>
				<view class="appeal">
					请到我的-蜂巢凭证中 进行下一步操作
				</view>
				<button type="default" class="button" @click="zhidao">前往查看</button>
			</view>
		</u-popup>
	</view>
</template>

<script>
	var than;
	export default {
		data() {
			return {
				background: {
					'background': 'transparent'
				},
				logistics: false,
				title: "",
				maid: "",
				count: "",
				notice: [],
				list: [],
				page: 1,
				orderno: "",
				sort_value: 1,
				timeout: 5000,
				timeout2: 500,
				index: 0,
				data: {},
				logo: "",
			}
		},
		onLoad(option) {
			than = this;
			than.maid = option.maid
			than.title = option.title
			than.logo = option.logo
			than.listOfOnsale()
			let open_start = option.open_start
			let open_end = option.open_end
			let hours = new Date().getHours();
			let minutes = new Date().getMinutes();
			let seconds = new Date().getSeconds();
			let h = than.mul(than.mul(hours, 60), 60)
			let m = than.mul(minutes, 60)
			var date = than.add(than.add(h, m), seconds);
			if (than.sub(date, open_start) > 1800) {
				than.doBuyList()
			} else {
				setTimeout(function() {
					than.doBuyList()
				}, than.mul(than.sub(1800, than.sub(date, open_start)), 100));
			}
		},
		onReachBottom() {
			than.page++;
			than.listOfOnsale()
		},
		methods: {
			sort() {
				than.sort_value = than.sort_value == 1 ? 2 : 1;
				than.page = 1;
				uni.showLoading({
					title: '请稍后'
				});
				this.$u.throttle(this.listOfOnsale, this.timeout);
				setTimeout(function() {
					uni.hideLoading();
				}, 5000);
			},
			doBuyList() {
				than.post("api/goods/doBuyList", {
					page: than.page,
					maid: than.maid
				}, function(data) {
					var arr = [];
					for (let i in data) {
						var name = data[i].nickname.substring(1, 0) + "**"
						var price = data[i].price
						arr.push("恭喜" + name + "成功抢拍价值" + price + "蜂巢")
					}
					if (than.page == 1) {
						than.notice = arr;
					} else {
						than.notice = than.notice.concat(arr)
					}
				})
			},
			getResult() {
				than.post("api/goods/doBuy", {
					page: than.page,
					pid: than.data.pid
				}, function(data) {
					console.log(2);
					than.orderno = data;
					than.list[than.index].show = false;
					than.logistics = true;
				})
			},
			doBuy(data, index) {
				than.data = data;
				than.index = index;
				this.$u.debounce(this.getResult, this.timeout2, false);
			},
			zhidao() {
				than.logistics = false;
				than.toPage('/pages/htmlB/voucher/index?orderno=' + than.orderno)
			},
			refresh() {
				than.page = 1;
				uni.showLoading({
					title: '请稍后'
				});
				than.$u.throttle(this.listOfOnsale, this.timeout);
				setTimeout(function() {
					uni.hideLoading();
				}, 5000);
			},
			listOfOnsale() {
				than.post("api/goods/listOfOnsale", {
					page: than.page,
					sort_value: than.sort_value,
					maid: than.maid
				}, function(data) {
					than.count = data.count;
					for (let i in data.list) {
						data.list[i].show = true
					}
					if (than.page == 1) {
						than.list = data.list;
					} else {
						than.list = than.list.concat(data.list)
					}
					/* setTimeout(function() {
						uni.hideLoading();
					}, 1000); */
				})
			}
		}
	}
</script>

<style lang="less">
	.notice {
		margin: 50rpx 24rpx 0;
		background-image: url(../../../static/image/pop5.png);
		background-size: 100% 100%;
		padding-left: 140rpx;
	}

	.nonetow {
		text-align: center;

		image {
			width: 678rpx;
			height: 281rpx;
		}

		.text {
			font-size: 28rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #333333;
			margin-top: 61rpx;

			text {
				font-size: 36rpx;
				color: #FFC31E;
			}
		}
	}

	page {
		background: #FAFAFA;
	}

	.fight {
		text-align: center;
		padding-bottom: 32rpx;

		.title_item {
			height: 113rpx;
			line-height: 113rpx;
			font-size: 32rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #333333;
			border-bottom: 1px solid #F6F6F6;
		}

		.appeal {
			margin-top: -20rpx;
			margin-bottom: 40rpx;
			padding: 0 250rpx;
			font-size: 24rpx;
			line-height: 36rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #666666;
		}

		.icon {
			text-align: center;

			image {
				width: 426rpx;
				height: 391rpx;
			}
		}

		.button {
			width: 245rpx;
			height: 74rpx;
			background: #FB683D;
			border-radius: 20rpx;
			font-size: 28rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #FFFFFF;
		}
	}

	.content {
		position: relative;
		z-index: 22;
		border-radius: 40rpx 40rpx 0rpx 0rpx;
		margin-top: 50rpx;
		width: 100%;

		.list {
			margin: 0 auto 24rpx;
			background: #FFFFFF;
			width: 678rpx;
			border-radius: 20rpx;
			height: 191rpx;
			position: relative;
			display: flex;
			align-items: center;

			.img {
				position: absolute;
				top: 1rpx;
				right: 19rpx;
				width: 50rpx;
				height: 50rpx;
			}

			.icon {
				margin-right: 60rpx;
				margin-left: auto;

				image {
					width: 77rpx;
					height: 77rpx;
				}

				.name {
					font-size: 26rpx;
					font-family: PingFang SC;
					font-weight: bold;
					color: #666666;
				}
			}

			.number {
				width: 250rpx;
				margin-left: 24rpx;

				.up {
					font-style: initial;
					font-size: 56rpx;
					font-family: Myriad Pro;
					font-weight: 400;
					color: #1B1B1B;

					text {
						margin-left: 10rpx;
						font-size: 32rpx;
					}
				}

				.down {
					display: initial;
					background: #F5E5D8;
					padding: 5rpx 9rpx;
					border-radius: 12rpx;
					font-size: 22rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #B8845C;
				}
			}
		}
	}

	.title {
		padding: 0 62rpx;
		height: 100rpx;
		line-height: 100rpx;
		background: #FFFFFF;
		border-radius: 40rpx 40rpx 0rpx 0rpx;
		font-size: 36rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #333333;

		.img {
			width: 390rpx;
			height: 50rpx;
			position: absolute;
			left: 218rpx;
			top: 25rpx;
		}
	}

	.top {
		
		height: 100rpx;
		display: flex;
		align-items: center;

		.left {
			padding-left: 61rpx;

			.name {
				font-size: 46rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #333333;
			}

			.text {
				font-size: 24rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #333333;

				text {
					font-weight: bold;
					color: #3362FA;
					font-size: 36rpx;
					margin: 0 10rpx;
				}
			}
		}

		.right {
			padding-right: 35rpx;
			margin-left: auto;
			display: flex;
			align-items: center;

			.list {
				text-align: center;

				image {
					width: 78rpx;
					height: 78rpx;
				}

				.name {
					font-size: 24rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #333333;
				}

				margin-left:40rpx;
			}
		}
	}
</style>
